import React, { Component } from 'react';

export class My extends Component {
	state = {
		user: {
			nickname: localStorage.getItem('nickname') || '未登录',
			isLogin: localStorage.getItem('token') ? true : false
		}
	}
	quit() {
		localStorage.removeItem('token')
		localStorage.removeItem('nickname')
		this.setState({
			user: {
				nickname: '',
				isLogin: false
			}
		})
	}
	render() {
		const { user: { nickname, isLogin } } = this.state
		return (
			<div>
				{!isLogin ?
					<div>
						<h3 onClick={ () => this.props.history.push('/login') }>点我登录/注册</h3>
					</div>
					:
					<div>
						<h3>欢迎用户： { nickname }</h3>
						<button onClick={ () => this.quit() }>退出登录</button>
					</div>}
			</div>
		);
	}
}

